﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Forbidden_Island
{
    public partial class HelicopterLift : Form
    {
        private frm main_form = null;

        public HelicopterLift(frm f)
        {
            main_form = f;
            InitializeComponent();
        }

        private void HelicopterLift_Load(object sender, EventArgs e)
        {
            pbPlayerOneGround.Click += new System.EventHandler(PictureBoxGround_Click);
            pbPlayerTwoGround.Click += new System.EventHandler(PictureBoxGround_Click);
            pbPlayerThreeGround.Click += new System.EventHandler(PictureBoxGround_Click);
            pbPlayerFourGround.Click += new System.EventHandler(PictureBoxGround_Click);
            pbPlayerOneFlight.Click += new System.EventHandler(PictureBoxFlight_Click);
            pbPlayerTwoFlight.Click += new System.EventHandler(PictureBoxFlight_Click);
            pbPlayerThreeFlight.Click += new System.EventHandler(PictureBoxFlight_Click);
            pbPlayerFourFlight.Click += new System.EventHandler(PictureBoxFlight_Click);
        }
        //set from form1, indicates which players to show on helicopter lift form (corresponds to players on clicked tile location)
        public void setActivePlayers(int playerOne, int playerTwo, int playerThree, int playerFour)
        {
            if (playerOne == 1)
                pbPlayerOneGround.Visible = true;
            else
                pbPlayerOneGround.Visible = false;
            if (playerTwo == 1)
                pbPlayerTwoGround.Visible = true;
            else
                pbPlayerTwoGround.Visible = false;
            if (playerThree == 1)
                pbPlayerThreeGround.Visible = true;
            else
                pbPlayerThreeGround.Visible = false;
            if (playerFour == 1)
                pbPlayerFourGround.Visible = true;
            else
                pbPlayerFourGround.Visible = false;
        }
        //picturebox click handler to move players on ground to helicopter lift
        private void PictureBoxGround_Click(object sender, EventArgs e)
        {
            //determine which pb was clicked
            PictureBox currentPB = (PictureBox)sender;
            if (currentPB == pbPlayerOneGround && pbPlayerOneGround.Visible == true)
            {
                pbPlayerOneGround.Visible = false;
                pbPlayerOneFlight.Visible = true;
            }
            if (currentPB == pbPlayerTwoGround && pbPlayerTwoGround.Visible == true)
            {
                pbPlayerTwoGround.Visible = false;
                pbPlayerTwoFlight.Visible = true;
            }
            if (currentPB == pbPlayerThreeGround && pbPlayerThreeGround.Visible == true)
            {
                pbPlayerThreeGround.Visible = false;
                pbPlayerThreeFlight.Visible = true;
            }
            if (currentPB == pbPlayerFourGround && pbPlayerFourGround.Visible == true)
            {
                pbPlayerFourGround.Visible = false;
                pbPlayerFourFlight.Visible = true;
            }
            btnConfirm.Enabled = true;
            main_form.setLiftPlayers(pbPlayerOneFlight.Visible, pbPlayerTwoFlight.Visible, pbPlayerThreeFlight.Visible, pbPlayerFourFlight.Visible);
        }
        private void PictureBoxFlight_Click(object sender, EventArgs e)
        {
            //determine which pb was clicked
            PictureBox currentPB = (PictureBox)sender;
            if (currentPB == pbPlayerOneFlight && pbPlayerOneFlight.Visible == true)
            {
                pbPlayerOneGround.Visible = true;
                pbPlayerOneFlight.Visible = false;
            }
            if (currentPB == pbPlayerTwoFlight && pbPlayerTwoFlight.Visible == true)
            {
                pbPlayerTwoGround.Visible = true;
                pbPlayerTwoFlight.Visible = false;
            }
            if (currentPB == pbPlayerThreeFlight && pbPlayerThreeFlight.Visible == true)
            {
                pbPlayerThreeGround.Visible = true;
                pbPlayerThreeFlight.Visible = false;
            }
            if (currentPB == pbPlayerFourFlight && pbPlayerFourFlight.Visible == true)
            {
                pbPlayerFourGround.Visible = true;
                pbPlayerFourFlight.Visible = false;
            }
            if (pbPlayerOneFlight.Visible == false && pbPlayerTwoFlight.Visible == false && pbPlayerThreeFlight.Visible == false &&
               pbPlayerFourFlight.Visible == false)
                btnConfirm.Enabled = false;
            main_form.setLiftPlayers(pbPlayerOneFlight.Visible, pbPlayerTwoFlight.Visible, pbPlayerThreeFlight.Visible, pbPlayerFourFlight.Visible);
        }
        private void btnConfirm_Click(object sender, EventArgs e)
        {
            //if (pbPlayerOneFlight.Visible == false && pbPlayerTwoFlight.Visible == false && pbPlayerThreeFlight.Visible == false &&
            //    pbPlayerFourFlight.Visible == false)
            //{
            //    MessageBox.Show(btnConfirm, "You must select at least one player in order to use the helicopter lift.", "No Players Selected");
            //}
            //else
            //{
            main_form.setLiftStatus(true);
            main_form.setBannerText("Helicopter lift takeoff successful!  Click the tile where you'd like to land.");
            main_form.appendGameHistoryText("Helicopter lift takeoff successful!  Click the tile where you'd like to land.");
            HelicopterLift.ActiveForm.Close();
            //}
        }
        private void btnCancel_Click(object sender, EventArgs e)
        {
            main_form.setLiftStatus(false);
            HelicopterLift.ActiveForm.Close();
        }
    }
}
